package com.dmooo.ymx.malladapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dmooo.ymx.R;
import com.dmooo.ymx.config.Constants;
import com.dmooo.ymx.mall.MallGoodsDetailsActivity;
import com.dmooo.ymx.mallbean.ShopMallGoodsBean;
import com.dmooo.ymx.merchantbean.Authbean;
import com.dmooo.ymx.merchantbean.Merchantlistbean;
import com.dmooo.ymx.utils.StickHeaderDecoration;

import java.text.DecimalFormat;
import java.util.List;


public class MallHomeFirstAdapter extends BaseMultiItemQuickAdapter<ShopMallGoodsBean, BaseViewHolder>  {

    private List<ShopMallGoodsBean> lists;
    DecimalFormat df = new DecimalFormat("0.00");

    public MallHomeFirstAdapter(@Nullable List<ShopMallGoodsBean> data) {
        super(data);
//        addItemType(ShopMallGoodsBean.TEXT, R.layout.sort_header);
        addItemType(ShopMallGoodsBean.IMG, R.layout.shop_mall_goods_item);
    }

    @Override
    protected void convert(BaseViewHolder holder, ShopMallGoodsBean item) {
//        if (holder.getItemViewType() == 1) {
            //设置图片
            ImageView imageView = holder.getView(R.id.image);
            Glide.with(mContext).load(item.img.contains("http") ? item.img : Constants.APP_IP + item.img).error(R.mipmap.logo_app).dontAnimate().into(imageView);
            ((TextView) holder.getView(R.id.title_child)).setText(item.goods_name);
            holder.setText(R.id.tx2, "￥"+item.price);
                    holder.setText(R.id.tx2_2 ,item.old_price);
            TextView tx2_2 = holder.getView(R.id.tx2_3);
            tx2_2.setText("已售" + item.sales_volume);
            holder.setText(R.id.title_child2,"预估赚:"+item.commission);
            holder.setText(R.id.tx5, "赠送积分:" + item.give_point);
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putString("goods_id", item.goods_id);
                    Intent intent = new Intent(mContext, MallGoodsDetailsActivity.class);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }
            });
//        } else {
//            TextView t = holder.getView(R.id.txt_two);
//            t.setText("销量");
//            t = holder.getView(R.id.txt_three);
//            t.setText("价格");
//            t = holder.getView(R.id.txt_four);
//            t.setText("最新上架");
//            holder.addOnClickListener(R.id.txt_one).addOnClickListener(R.id.txt_two).addOnClickListener(R.id.txt_three).addOnClickListener(R.id.txt_four);
//        }
    }

//    @Override
//    public boolean isStick(int position) {
//        return position == 10000;
//    }
//
//    @Override
//    public void setOnHeaderClickListener(View view) {
//                Log.d("dfsadf",view.getId()+"  "+(view.getId()==R.id.txt_one));
//    }
}
